


*** Clean up Raw Denominator Files Received ***;

options ls=76 nofmterr;

libname raw '/data/Medicare_P01_2009/data/HEDIS/rawdata';
libname new '/data/Medicare_P01_2009/data/HEDIS/sasdata';
libname plan '/data/Medicare_P01_2009/data/HEDIS/plandata';


data a1(drop=id_num); set raw.linkid2004;

     proc sort; by hic_number;


data a2; set raw.denom2004;

     if can=' ' then delete;

     length hic_number $ 12;

     hic_number=can||obic;

     proc sort; by hic_number;

data denom; merge a1(in=a) a2(in=b); by hic_number;

     if a and b;

     denom_flag=1;

     length racec gender agec $ 10;

          if race=1 then racec='1.White';
     else if race=2 then racec='2.Black';
     else if race=3 then racec='3.Other';
     else if race=4 then racec='4.Asian';
     else if race=5 then racec='5.Hispanic';
     else if race=6 then racec='6.Native';
     else racec='0.Unknown';

     if sex=1 then gender='1.Male';
     if sex=2 then gender='2.Female';

     if age>0   and age<20 then agec='1-20 yr';
     if age>=20 and age<30 then agec='20-29 yrs';
     if age>=30 and age<40 then agec='30-39 yrs';
     if age>=40 and age<50 then agec='40-49 yrs';
     if age>=50 and age<60 then agec='50-59 yrs';
     if age>=60 and age<65 then agec='60-64 yrs';
     if age>=65 and age<70 then agec='65-69 yrs';
     if age>=70 and age<75 then agec='70-74 yrs';
     if age>=75 and age<80 then agec='75-79 yrs';
     if age>=80 and age<85 then agec='80-84 yrs';
     if age>=85            then agec='85+';

      *** Add State Ab and Region Variables ***;

    if state='01' then state_ab='AL' ;    if state='02' then state_ab='AK' ;
    if state='03' then state_ab='AZ' ;    if state='04' then state_ab='AR' ;
    if state='05' then state_ab='CA' ;    if state='06' then state_ab='CO' ;
    if state='07' then state_ab='CT' ;    if state='08' then state_ab='DE' ;
    if state='09' then state_ab='DC' ;    if state='10' then state_ab='FL' ;

    if state='11' then state_ab='GA' ;    if state='12' then state_ab='HI' ;
    if state='13' then state_ab='ID' ;    if state='14' then state_ab='IL' ;
    if state='15' then state_ab='IN' ;    if state='16' then state_ab='IA' ;
    if state='17' then state_ab='KS' ;    if state='18' then state_ab='KY' ;
    if state='19' then state_ab='LA' ;    if state='20' then state_ab='ME' ;

    if state='21' then state_ab='MD' ;    if state='22' then state_ab='MA' ;
    if state='23' then state_ab='MI' ;    if state='24' then state_ab='MN' ;
    if state='25' then state_ab='MS' ;    if state='26' then state_ab='MO' ;
    if state='27' then state_ab='MT' ;    if state='28' then state_ab='NE' ;
    if state='29' then state_ab='NV' ;    if state='30' then state_ab='NH' ;

    if state='31' then state_ab='NJ' ;    if state='32' then state_ab='NM' ;
    if state='33' then state_ab='NY' ;    if state='34' then state_ab='NC' ;
    if state='35' then state_ab='ND' ;    if state='36' then state_ab='OH' ;
    if state='37' then state_ab='OK' ;    if state='38' then state_ab='OR' ;
    if state='39' then state_ab='PA' ;    if state='40' then state_ab='PR';

    if state='41' then state_ab='RI' ;    if state='42' then state_ab='SC' ;
    if state='43' then state_ab='SD' ;    if state='44' then state_ab='TN' ;
    if state='45' then state_ab='TX' ;    if state='46' then state_ab='UT' ;
    if state='47' then state_ab='VT' ;    if state='48' then state_ab='GU';
    if state='49' then state_ab='VA' ;    if state='50' then state_ab='WA' ;

    if state='51' then state_ab='WV' ;    if state='52' then state_ab='WI' ;
    if state='53' then state_ab='WY' ;    

    length region9 region4 $ 25; 

    if state_ab in ('CT','MA','ME','NH','RI','VT')                then region9='1.New England';
    if state_ab in ('NJ','NY','PA')                               then region9='2.Mid Atlantic'; 
    if state_ab in ('WI','MI','IL','IN','OH')                     then region9='3.East North Central'; 
    if state_ab in ('ND','SD','NE','KS','MN','IA','MO')           then region9='4.West North Central'; 
    if state_ab in ('DE','MD','DC','FL','GA','NC','SC','VA','WV') then region9='5.South Atlantic';
    if state_ab in ('KY','TN','MS','AL')                          then region9='6.East South Central'; 
    if state_ab in ('OK','AR','TX','LA')                          then region9='7.West South Central';
    if state_ab in ('MT','ID','WY','NV','UT','CO','AZ','NM')      then region9='8.Mountain'; 
    if state_ab in ('WA','OR','CA','HI','AK')                     then region9='9.Pacific';

    if region9='1.New England' or 
       region9='2.Mid Atlantic'        then region4='Region 1: Northeast';
    if region9='3.East North Central' or 
       region9='4.West North Central'  then region4='Region 2: Midwest';
    if region9='5.South Atlantic' or 
       region9='6.East South Central' or 
       region9='7.West South Central' then region4='Region 3: South';
    if region9='8.Mountain' or 
       region9='9.Pacific'             then region4='Region 4: West';


     zip5=1*substr(zip,1,5);

     proc sort; by zip5;

data zip; set new.zipinfo;

     proc sort; by zip5;

data new.hedis04denom; merge denom(in=ok) zip; by zip5;

     if ok;  
 
     proc freq; tables gender racec;


endsas;

